import {reqLoginList} from '@/api';

//login模块的仓库
const state = {
  //登录接口返回的token
  token: sessionStorage.getItem("GETTOKEN"),
};
const mutations = {
  USERLOGIN(state,token) {
    state.token = token;
    sessionStorage.setItem("GETTOKEN", token);
  }
};
const actions = {
  async userLogin({commit},data){
    let result = await reqLoginList(data);
    if(result.code==200){
      commit('USERLOGIN',result.data.token);
      return '成功！'
    }else {
      return Promise.reject(new Error(result.msg));
    }
  },
};
//计算属性
const getters = {};

//对外暴露store类的一个实例
export default {
  state,
  mutations,
  actions,
  getters,
};